<template>
<view>
<!-- <loading v-if="!show">加载中...</loading> -->
<view class="page">
    <view @tap="previewImage" class="fui-picture">
        <image @load="loadImg" :src="Image" v-if="Image.length>0"></image>
    </view>
    <view @tap="savePicture" class="save-btn">保存图片</view>
    <view class="explain-navbar">
        <i class="icox icox-zhuyi"></i>
        <view class="expl">保存至相册</view>
    </view>
    <!-- <view :class="'fui-toast ' + (FoxUIToast.show?'in':'out')">
        <view class="text">{{FoxUIToast.text}}</view>
    </view> -->
</view>
</view>
</template>

<script>
var t = getApp().globalData,
    e = t.requirejs("core"),
    s = t.requirejs("foxui");

export default {
  data() {
    return {
      show: !1,
      accredit: "",
      errMsg: "",
      Image: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (t) {
    (t = t || {}).id ? this.getImage(t.id) : wx.redirectTo({
      url: "/pages/goods/index/index"
    });
  },
  methods: {
    getImage: function (t) {
      var o = this;
      e.json("goods/poster/getimage", {
        id: t
      }, function (t) {
        0 != t.error ? s.toast(o, t.message) : o.setData({
          Image: t.url
        });
      });
    },
    loadImg: function (t) {
      this.setData({
        show: !0
      });
    },
    previewImage: function () {
      wx.previewImage({
        current: this.Image,
        urls: [this.Image]
      });
    },
    savePicture: function () {
      var t = this;
      wx.getSetting({
        success: function (e) {
          e.authSetting["scope.writePhotosAlbum"] ? (wx.showLoading({
            title: "图片下载中..."
          }), setTimeout(function () {
            wx.hideLoading();
          }, 1e3), wx.downloadFile({
            url: getApp().globalData.Image,
            success: function (e) {
              wx.saveImageToPhotosAlbum({
                filePath: e.tempFilePath,
                success: function (e) {
                  s.toast(t, "保存图片成功");
                },
                fail: function (e) {
                  t.setData({
                    errMsg: e.errMsg
                  }), s.toast(t, "保存图片失败");
                }
              });
            }
          })) : wx.authorize({
            scope: "scope.writePhotosAlbum",
            success: function () {
              wx.showLoading({
                title: "图片下载中..."
              }), setTimeout(function () {
                wx.hideLoading();
              }, 1e3), wx.downloadFile({
                url: getApp().globalData.Image,
                success: function (e) {
                  wx.saveImageToPhotosAlbum({
                    filePath: e.tempFilePath,
                    success: function (e) {
                      s.toast(t, "保存图片成功");
                    },
                    fail: function (e) {
                      t.setData({
                        errMsg: e.errMsg
                      }), s.toast(t, "保存图片失败");
                    }
                  });
                }
              });
            },
            fail: function () {
              wx.showModal({
                title: "警告",
                content: "您点击了拒绝授权，将无法正常使用保存图片或视频的功能体验，请删除小程序重新进入。"
              });
            }
          });
        }
      });
    }
  }
};
</script>
<style>
@import "./poster.css";
</style>